home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / conv.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  3KB  |  85 lines

  1.  /********************************************************
  2.  *                                                       *
  3.  *              C O N V E R T                            *
  4.  *                                                       *
  5.  * This function provides a service utility for the      *
  6.  * ASCII/DKOI (EBCDIC) conversion. It works with the     *
  7.  * specified character string and produces a converted   *
  8.  * character string.                                     *
  9.  *                                                       *
  10.  * As the matter of fact, at present this subroutine     *
  11.  * has sense for Russia only. For LU 6.2 customizing     *
  12.  * you have to supply your own national alphabet.        *
  13.  *                                                       *
  14.  * Input : Pointer to "convert" structure.               *
  15.  * Output: rc in "convert" struct. indicates             *
  16.  * whether the conversion was successful or not.         *
  17.  *                                                       *
  18.  * CopyRight 1995. Nicholas Poljakov all rights reserved.*
  19.  *                                                       *
  20.  ********************************************************/
  21. #include <convert.h>
  22. #include <stdio.h>
  23. #include <state1.h>
  24.  
  25. #define  ASCII_TO_EBCDIC    0
  26. #define  EBCDIC_TO_ASCII    1
  27. #define  ASCIIm_TO_EBCDIC   2
  28. #define  EBCDIC_TO_ASCIIm   3
  29. #define  ASCIIint_TO_EBCDIC 4
  30. #define  EBCDIC_TO_ASCIIint 5
  31. #define  AE                 0
  32. #define  Aa                 1
  33. #define  G                  2
  34. int trans(void *, void *, int, char);
  35.  
  36. conv(ptr)
  37. struct convert *ptr;
  38. {
  39.         char *in;
  40.         char *out;
  41.         int  length;
  42.     char table;
  43.  
  44.         ptr -> rc = OK;
  45.         switch (ptr -> direct) {
  46.                 case ASCII_TO_EBCDIC :
  47.                 case EBCDIC_TO_ASCII :
  48.                 case ASCIIm_TO_EBCDIC :
  49.                 case EBCDIC_TO_ASCIIm :
  50.                 case ASCIIint_TO_EBCDIC :
  51.                 case EBCDIC_TO_ASCIIint : break;
  52.                 default :
  53.                          {
  54.                              ptr -> rc = 0x00000401; /* Invalid direction */
  55.                              return (0);
  56.                          }
  57.          }
  58.          switch (ptr -> ch_set) {
  59.                 case AE :
  60.         case Aa :
  61.                 case G : break;
  62.                 default :
  63.                          {
  64.                              ptr -> rc = 0x00000402; /* Invalid type */
  65.                              return (0);
  66.                          }
  67.           }
  68.           if (ptr -> target == NULL) {
  69.                 ptr -> rc = 0x00000404; /* Invalid first char. */
  70.                 return (0);
  71.           }
  72.           if (ptr -> source == NULL) {
  73.                 ptr -> rc = 0x00000403; /* Segment overlap */
  74.                 return (0);
  75.           }
  76.           in = ptr -> source;
  77.           out = ptr -> target;
  78.           length = ptr -> length;
  79.           table = ptr -> direct;
  80.           if (trans(out, in, length, table) == -1) {
  81.                 ptr -> rc = 0x00000405; /* Table error */
  82.                 return (0);
  83.           }
  84. }
  85.